import numpy as np
import pandas as pd
s1 = pd.Series([1,4,7,10])
print('使用列表创建的Series对象s1: \n',s1)
arr = np.array([1,4,7,10])
s2 = pd.Series(arr, ['a','b','c','d'])
print('使用数组创建的Series对象s2: \n',s2)
s3 = pd.Series({'a':1,'b':4,'c':7,'d':10})
print('使用字典创建的Series对象s3: \n',s3)


import pandas as pd
index = ['王蒙','李珊','赵胜','刘文']
columns = ['语文','数学','英语']
dict = {'语文':[110,95,98,112],'数学':[120,110,80,106],'英语':[105,108,100,97]}
df1 = pd.DataFrame(dict,index)
print('使用字典创建的DataFarme对象df1: \n',df1)
s1 = pd.Series([110,120,105],columns)
s2 = pd.Series([95,110,108],columns)
s3 = pd.Series([98,80,100],columns)
s4 = pd.Series([112,106,97],columns)
df2 = pd.DataFrame([s1,s2,s3,s4],index)
print('使用Series对象创建的DataFrame对象df2: \n',df2)


import pandas as pd
list = [[110,120,105],[95,110,108],[98,80,100],[112,106,97]]
index = ['王蒙','李珊','赵胜','刘文']
columns = ['语文','数学','英语']
df = pd.DataFrame(list,index,columns)
print('原始数据: \n',df)
print('选取所有学生的语文成绩: \n',df['语文'])
print('选取所有学生的语文和数学成绩: \n',df[['语文','数学']])
print('选取王蒙到赵胜的语文和英语成绩: \n',df[['语文','英语']]['王蒙':'赵胜'])
print('选取李珊及后面学生的所有成绩: \n',df[['语文','数学','英语']]['李珊':])


import pandas as pd
list = [[110,120,105],[95,110,108],[98,80,100],[112,106,97]]
index = ['王蒙','李珊','赵胜','刘文']
columns = ['语文','数学','英语']
df = pd.DataFrame(list,index,columns)
print('原始数据: \n',df)
print('选取王蒙的所有成绩: \n',df.loc['王蒙'])
print('选取王蒙和刘文的所有成绩: \n',df.loc[['王蒙','刘文']])
print('选取王蒙到赵胜的所有成绩: \n',df.loc['王蒙':'赵胜'])
print('选取王蒙和赵胜的语文和数学成绩: \n',df.loc[['王蒙','赵胜'],['语文','数学']])
print('选取王蒙到赵胜的语文和英语成绩: \n',df.loc['王蒙':'赵胜',['语文','英语']])


import pandas as pd
list = [[110,120,105],[95,110,108],[98,80,100],[112,106,97]]
index = ['王蒙','李珊','赵胜','刘文']
columns = ['语文','数学','英语']
df = pd.DataFrame(list,index,columns)
print('原始数据: \n',df)
print('选取王蒙的所有成绩: \n',df.iloc[0])
print('选取王蒙和刘文的所有成绩: \n',df.iloc[[0,3]])
print('选取王蒙到赵胜的所有成绩: \n',df.iloc[0:3])
print('选取王蒙和赵胜的语文和数学成绩: \n',df.iloc[[0,2],[0,1]])
print('选取王蒙到赵胜的语文和英语成绩: \n',df.iloc[0:3,[0,2]])







#列2-4到2-5
# import numpy as np
# arr = np.array([[1,2,3],[4,5,6],[7,8,9],[10,11,12]])
# print('4X3的整数数组为: \n', arr)
# print('数组的ndim属性:                              ',arr.ndim)
# print('数组的shape属性:',arr.shape)
# print('数组的size属性:',arr.size)
# print('数组的dtype属性:',arr.dtype)

import numpy as np
arr = np.array([[1,2,3,4],[5,6,7,8],[9,10,11,12]])
print('3x4的数组: \n',arr)
print('第1行第3列的元素:',arr[0,2])
print('第1~2行第2~3列的元素 \n',arr[0:2,1:3])
print('第3行、列长为2的元素',arr[2,::2])
print('行长为2、第1~2列的元素: \n',arr[::2,:2])











#第2章






